package com.ghn.cocknovel.ui.activity.myorder

import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.example.basemodel.base.BaseHeadVMActivity
import com.example.basemodel.base.DefaultHeadStyle
import com.ghn.cocknovel.R
import com.ghn.cocknovel.databinding.ActivityMyOrderContentBinding
import com.ghn.cocknovel.databinding.ActivityMyorderBinding
import com.ghn.cocknovel.ui.activity.myorder.vm.MyorderViewModel

class MyOrderContentActivity :
    BaseHeadVMActivity<MyorderViewModel, ActivityMyOrderContentBinding, DefaultHeadStyle>() {
    override fun layoutId()=R.layout.activity_my_order_content

    @RequiresApi(Build.VERSION_CODES.M)
    override fun initView(savedInstanceState: Bundle?) {
        mHeadStyle.setTitleColor("订单详情", getColor(R.color.black))
        mHeadStyle.setTitleBackgroundColor(getColor(R.color.gray4))

        mViewModel.queryTransitOrder(intent.getStringExtra("orderId").toString())
        mViewModel.queryTransitOrder.observe(this){
            Log.i("TAG", "initView: $it")
            mDatabind.OrderContentNumber.text=it?.orderId
            mDatabind.OrderContentTime.text=it?.createTime
            if (!TextUtils.isEmpty(it?.returnReason)){
                mDatabind.OrderContentReason.text=it?.returnReason
            }else{
                mDatabind.llyOrderContentReason.visibility=View.GONE
            }


            mDatabind.OrderContentUpAddress.text=it?.originAddress
            mDatabind.OrderContentDebusAddress.text=it?.destinationAddress
            if (it?.goTime!=null){
                mDatabind.OrderContentDebusTime.text= it.goTime.toString()
            }else{
                mDatabind.llyOrderContentDebusTime.visibility=View.GONE
            }
            if (it?.offTime!=null){
                mDatabind.OrderContentUpDebusTime.text= it.offTime.toString()
            }else{
                mDatabind.llyOrderContentUpDebusTime.visibility=View.GONE
            }


            mDatabind.OrderContentCarNumber.text=it?.carNumber
            mDatabind.OrderContentAmount.text="¥"+it?.orderOriginAmount.toString()
            mDatabind.OrderContentDiscount.text="¥"+it?.orderDiscountAmount.toString()
            mDatabind.OrderContentPaid.text="¥"+it?.orderPaymentAmount.toString()
            when (it?.orderStatus) {
                1 -> {
                    mDatabind.OrderContentType.text =
                        "待支付"
                }

                2 -> {
                    mDatabind.OrderContentType.text =
                        "待呼叫"
                }

                3 -> {
                    mDatabind.OrderContentType.text =
                        "呼叫中"
                }

                4 -> {
                    mDatabind.OrderContentType.text =
                        "司机已接单"
                }

                5 -> {
                    mDatabind.OrderContentType.text =
                        "司机到达"
                }

                6 -> {
                    mDatabind.OrderContentType.text =
                        "已上车"
                }

                7 -> {
                    mDatabind.OrderContentType.text =
                        "行程结束"
                }

                8 -> {
                    mDatabind.OrderContentType.text =
                        "已取消"
                }

                9 -> {
                    mDatabind.OrderContentType.text =
                        "已退款"
                }

            }
            when(it?.payCode){
                1->{
                    mDatabind.OrderContentMethod.text="微信"
                }
            }
        }
    }


    override fun createObserver() {

    }
}